package com.theBlind.orm;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @program: orm
 * @description: 参数处理
 * @author: TheBlind
 * @create: 2021-04-23 17:08
 **/
public class ParameterHandle {

    public boolean setOneParameter(PreparedStatement preparedStatement, Object parameter,int i) throws SQLException {
        //判断是否为单个入参
        if (parameter instanceof Long) {
                preparedStatement.setLong(i, Long.parseLong(parameter.toString()));
            return true;
        }
        if (parameter instanceof Integer) {
                preparedStatement.setInt(i, Integer.parseInt(parameter.toString()));
            return true;
        }
        if (parameter instanceof String) {
                preparedStatement.setString(i, parameter.toString());
            return true;
        }
        return false;
    }

    public void setParameter(PreparedStatement preparedStatement, Object parameter, Map<String, Integer> parameterMap) throws SQLException {
        int size = parameterMap.size();
        //是否为Map
        if (parameter instanceof Map) {
           Map v1=(Map) parameter;
            Set keySet = v1.keySet();

            Iterator<String> it = keySet.iterator();

            while (it.hasNext()) {

                String key = it.next();
                Object var = v1.get(key);
            }
            for (int i = 1; i <= size; i++) {
                preparedStatement.setString(i, parameter.toString());
            }
            return;
        }





    }








}
